<?php
	//var_dump($_POST);

	require_once('Class/connexionDB.Class.php');
	require_once('Class/PHPMailer/PHPMailerAutoload.php');

	$db 		= new connexionDB();
	
	$result 		= $db->getSavedMail();

	$mail_subject 	= $result['mail_subject'];
	$mails_adress	= $db->getMailAdressActivated();
	$mail_body 		= $result['mail_body'];
	

	//var_dump($mails_adress, $mail_subject, $mail_body);
	
	if (count($mails_adress) != 0 && $mail_subject != '' && $mail_body != '')
	{
		$mail = new PHPMailer();
	
		$mail->CharSet 			= 'UTF-8';
		$mail->isSMTP();
		$mail->Host 			= '192.168.1.65';					//HOST mail

		$mail->From 			= 'quality.monitoring@showroomprive.com';
		$mail->FromName 		= 'Quality Monitoring';

		foreach ($mails_adress as $key => $mail_adress)
		{
			$mail->addAddress($mail_adress['mail']);	
		}

		$mail->isHTML(true);
		$mail->Subject 			= $mail_subject;
		$mail->Body    			= $mail_body;
		//var_dump($mail);
		if(!$mail->send())
		{
		    echo 'Message could not be sent.';
		    echo 'Mailer Error : ' . $mail->ErrorInfo;
		} 
		else 
		{
		    echo 'Message has been sent';
		}
	}
?>
